package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.app.entity.GrabTicketsRecordingEntity;
import io.renren.modules.app.service.GrabTicketsRecordingService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 收抢票记录表
 *
 * @date 2022-04-20 22:37:45
 */
@RestController
@RequestMapping("app/grabticketsrecording")
public class GrabTicketsRecordingController {
    @Autowired
    private GrabTicketsRecordingService grabTicketsRecordingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:grabticketsrecording:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = grabTicketsRecordingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{grabTicketsId}")
    @RequiresPermissions("generator:grabticketsrecording:info")
    public R info(@PathVariable("grabTicketsId") Long grabTicketsId) {
        GrabTicketsRecordingEntity grabTicketsRecording = grabTicketsRecordingService.getById(grabTicketsId);

        return R.ok().put("grabTicketsRecording", grabTicketsRecording);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:grabticketsrecording:save")
    public R save(@RequestBody GrabTicketsRecordingEntity grabTicketsRecording) {
        grabTicketsRecording.setMatchingTime(new Date());
        grabTicketsRecordingService.save(grabTicketsRecording);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:grabticketsrecording:update")
    public R update(@RequestBody GrabTicketsRecordingEntity grabTicketsRecording) {
        grabTicketsRecordingService.updateById(grabTicketsRecording);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:grabticketsrecording:delete")
    public R delete(@RequestBody Long[] grabTicketsIds) {
        grabTicketsRecordingService.removeByIds(Arrays.asList(grabTicketsIds));

        return R.ok();
    }

}
